

function randomRgbaColor() { //随机生成RGBA颜色
    var r = Math.floor(Math.random() * 256); //随机生成256以内r值
    var g = Math.floor(Math.random() * 256); //随机生成256以内g值
    var b = Math.floor(Math.random() * 256); //随机生成256以内b值
    var alpha = 1; //随机生成1以内a值
    return `rgba(${r},${g},${b},${alpha})`; //返回rgba(r,g,b,a)格式颜色
}

var arr=[];

for(var i=0;i<xianlu.length;i++){

    var singleLine = {
        "id":"",
        "coords": [],
        "lineStyle": {
            "normal": {
                "color": "rgba(223,90,90,1)"
            }
        }
    }

    singleLine.lineStyle.normal.color = randomRgbaColor();
    singleLine.id = xianlu[i].patrolId;
    for(var j=0;j<xianlu[i].track.length;j++){
        var lon = xianlu[i].track[j].lon;
        var lat = xianlu[i].track[j].lat;
        singleLine.coords.push([lon,lat])
    }

    arr.push(singleLine);
}

var myChart = echarts.init(document.getElementById('main'));
var uploadedDataURL = "./js/jiangxi.json";
$.getJSON(uploadedDataURL, function (geoJson) {
   echarts.registerMap('jiangxi', geoJson);
    myChart.hideLoading();
    var busLines = arr
    console.log(busLines);
    var option = {
        geo: {
            type: 'map',
            map: 'jiangxi',
            selectedMode: 'single',
            roam: true,
            itemStyle: {
                normal: {
                    areaColor: '#d6fff3',
                    borderColor: '#111'
                },
                emphasis: {
                    areaColor: '#d6fff3'
                }
            },
            // center: [116.46, 39.92],
            // zoom: 10,
            roam: true,
        },
        series: [{
            type: 'lines',
            coordinateSystem: 'geo',
            polyline: true,
            data: busLines,
            silent: true,
            lineStyle: {
                normal: {
                    // color: '#c23531',
                    // color: 'rgb(200, 35, 45)',
                    opacity: 0.2,
                    width: 1
                }
            },
            progressiveThreshold: 500,
            progressive: 200
        }, {
            type: 'lines',
            coordinateSystem: 'geo',
            polyline: true,
            data: busLines,
            lineStyle: {
                normal: {
                    width: .3
                }
            },
            effect: {
                constantSpeed: 30,
                show: true,
                trailLength: .3,
                symbolSize: 4
            },
            zlevel: 1
        }]
    };

    myChart.on('click', function (params) {
        console.log(params.data.id);
    });


    myChart.setOption(option);
    myChart.resize();
    setTimeout(function () {
        window.addEventListener("resize", function () {
            myChart.resize();
        }, 200)
    });
});